/**
 * 动作 告警方式
 * @param app
 * @returns {*}
 */
module.exports = app => {
  const mongoose = app.mongoose
  const { Schema } = mongoose
  const { ObjectId } = Schema

  const modelSchema = new Schema({
    name: { type: String, remark: '告警方式名称', required: true },
    type: {
      type: Number,
      default: 0,
      enum: {
        0: '邮件告警',
        1: '短信告警',
        2: 'webhook 告警',
        3: 'webscoket',
      },
      remark: '告警方式',
    },
    config: {
      type: Object,
      required: true,
      like: {
        email: 'bigpar@qq.com',
        title: '数据流错误',
        content: '你的主机${hostname}数据${name}异常',
      },
      remark: '详细配置',
    },
    user: { type: ObjectId, required: true, ref: 'user', remark: '创建用户' },
  }, {
    collections: 'action',
    timestamps: true,
  })

  modelSchema.index({ name: 1 })

  return mongoose.model('action', modelSchema)
}